package com.xmg.p2p.base.controller;

import com.xmg.p2p.base.domain.Logininfo;
import com.xmg.p2p.base.domain.Userinfo;
import com.xmg.p2p.base.interceptor.RequireLogin;
import com.xmg.p2p.base.service.ISystemDictionaryItemService;
import com.xmg.p2p.base.service.IUserinfoService;
import com.xmg.p2p.base.util.JSONResult;
import com.xmg.p2p.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * lcd  2020/5/14
 * Description:
 */
@Controller
public class BasicInfoController {
    @Autowired
    private IUserinfoService userinfoService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @RequireLogin
    @RequestMapping("basicInfo")
    public String basicInfo(Model model){
        Logininfo logininfo = UserContext.getLogininfo();
        Userinfo userinfo = userinfoService.findById(logininfo.getId());
        model.addAttribute("userinfo", userinfo);
//        model.addAttribute("logininfo", logininfo);
        model.addAttribute("educationBackgrounds", systemDictionaryItemService.queryBySn("educationBackground"));
        model.addAttribute("incomeGrades", systemDictionaryItemService.queryBySn("incomeGrade"));
        model.addAttribute("marriages", systemDictionaryItemService.queryBySn("marriage"));
        model.addAttribute("kidCounts", systemDictionaryItemService.queryBySn("kidCount"));
        model.addAttribute("houseConditions", systemDictionaryItemService.queryBySn("houseCondition"));
        return "userInfo";
    }

    @RequireLogin
    @RequestMapping("basicInfo_save")
    @ResponseBody
    public JSONResult basicInfo_save(Userinfo userinfo){
        userinfoService.updateBasicInfo(userinfo);
        return new JSONResult();
    }




}
